package com.oig.sys.base.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oig.common.constants.CommonEnum;
import com.oig.common.module.SysRequest;
import com.oig.sys.base.dto.CountryDto;
import com.oig.sys.base.mapper.TbCountryMapper;
import com.oig.sys.base.vo.CountryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "国别地区查询")
@RestController
@RequestMapping(value = "/country")
@RequiredArgsConstructor
@Slf4j
//@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class TbCountryController {

    private final TbCountryMapper countryMapper;


    /**
     * 普通查询
     */
    @Operation(summary = "查询国别地区,公共功能，不设权限登，录即可")
    @PostMapping("/page")
    public PageInfo<CountryVo> queryAsPage(@RequestBody SysRequest<CountryDto> sysRequest){
        log.info("country query 2:{}", sysRequest);
        PageHelper.startPage(sysRequest.getPageNo(), sysRequest.getPageSize());
        if (sysRequest.getParamDto()==null){
            sysRequest.setParamDto(new CountryDto());
        }
        if (sysRequest.getParamDto().getStatus()==null){
            sysRequest.getParamDto().setStatus(CommonEnum.CommonStatusEnum.OK.getCode());
        }
        List<CountryVo> list = this.countryMapper.queryCountry(sysRequest.getParamDto());
        return new PageInfo<>(list);
    }

}
